<template>
  <div class="cmscomen newAccountNumber">
    <div class="infoTable" :style="{ paddingLeft: paddingWidth + 'px'}">
      <div class="topMenu">
        <span>信息流数据管理</span>
        <span style="padding:0 4px;">/</span>
        <span>账号管理</span>
        <span style="padding:0 4px;">/</span>
        <span class="two">新建账号</span>
      </div>
      <div class="wrapColor" :style="{ width: wraColrWidth}">
        <div class="mixTitle">创建账号信息</div>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="选择平台" prop="type">
            <el-select v-model="ruleForm.type" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="平台账号" required>
            <el-col :span="11">
              <el-form-item prop="loginNumber">
                <el-input v-model="ruleForm.loginNumber" placeholder="请输入登录账号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item prop="passWord">
                <el-input v-model="ruleForm.passWord" placeholder="请输入登录密码"></el-input>
              </el-form-item>
            </el-col>
          </el-form-item>
          <el-form-item label="运营人员" required>
            <el-col>
              <el-form-item prop="date">
                <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col>
              <el-form-item prop="userName">
                <el-input v-model="ruleForm.userName" placeholder="请输入运营人员姓名"></el-input>
              </el-form-item>
            </el-col>
            <el-col>
                <el-button type="primary" @click="add">添加一行</el-button>
            </el-col>
          </el-form-item>
          <el-form-item v-for="(items,index) in operators" :key="index" v-if="flag">
            <el-col>
              <el-form-item>
                <el-date-picker type="date" placeholder="选择日期" v-model="items.date"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col>
              <el-form-item>
                <el-input v-model="items.operatorId" placeholder="请输入运营人员姓名"></el-input>
              </el-form-item>
            </el-col>
            <el-col>
                <el-button type="danger" @click="deleted(index)">删除一行</el-button>
            </el-col>
          </el-form-item>
          <el-form-item style="padding-top:20px">
            <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
            <el-button type="info" @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import axios from 'axios';
export default {
  data(){
    return{
      flag:false,
      options: [{
          value: '选项1',
          label: '黄金糕'
        }, {
          value: '选项2',
          label: '双皮奶'
        }, {
          value: '选项3',
          label: '蚵仔煎'
        }, {
          value: '选项4',
          label: '龙须面'
        }, {
          value: '选项5',
          label: '北京烤鸭'
        }],
        ruleForm: {
            type: '',
            loginNumber: '',
            passWord:'',
            date: '',
            userName: '',
        },
        rules: {
          type: [
            { required: true, message: '请至少选择一个平台', trigger: 'change' }
          ],
          loginNumber: [
            { required: true, message: '请输入账号', trigger: 'blur' },
          ],
          passWord: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ],
          date: [
            { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
          ],
          userName: [
            { required: true, message: '请输入运营人员姓名', trigger: 'blur' }
          ],
        },
        operators: [],
    }
  },
  computed:{
    paddingWidth(){
      return this.$store.state.paddingWidth;
    },
    wraColrWidth(){
      return this.$store.state.wraColrWidth;
    }
  },
  created(){
  },
  methods:{
    submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    add(){
        this.flag = true;
        this.operators.push({
            "date": "",
            "id": null,
            "operatorId": ''
        });
    },
    deleted(index){
      this.operators.splice(index,1)
    }
  }
}
</script>
<style>
.newAccountNumber .titleName{
  font-size: 18px;
  font-weight: 700;
  padding-bottom: 30px;
  padding-top: 10px;
}
.newAccountNumber .el-form-item__label{
  text-align: left;
}
.newAccountNumber .el-form-item__content .el-input{
  width: 217px;
}
</style>